package cn.stylefeng.guns.modular.system.service.ActivityEvent;

import cn.stylefeng.guns.modular.system.entity.AfterSale;
import cn.stylefeng.guns.modular.system.service.AfterSaleService;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class WxAfterSaleEvent implements ExecutionListener {
    private AfterSaleService afterSaleService = SpringContextHolder.getBean(AfterSaleService.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
        AfterSale afterSale = afterSaleService.getOne(new QueryWrapper<AfterSale>()
                .lambda().eq(AfterSale::getProcessInstanceId,delegateExecution.getProcessInstanceId()));
        if ("end".equals(eventName)){
            afterSale.setStatus(StatusCode.FAIL.getVal());
        }else if ("start".equals(eventName)){
            afterSale.setStatus(StatusCode.SUCCESS.getVal());
        }
        afterSaleService.getBaseMapper().updateById(afterSale);
    }
}
